package su2010.puz.extractors;

import java.awt.image.BufferedImage;

import com.pearsoneduc.ip.op.HistogramException;

import su2010.puz.Extractor;
import su2010.puz.ImageHelper;
import su2010.puz.impl.Histogram;
import su2010.puz.util.ImageCls;

public class HistogramPeakExtractor implements Extractor {

	private Histogram histogram;
	private int color_mode;
	private int numOutput = 1;
	
	public HistogramPeakExtractor() {
		this.color_mode = ImageHelper.RED;
	}
	
	public void setColorMode(int mode) {
		this.color_mode = mode;
	}
	
	public void setImage(BufferedImage image) {
		try {
			histogram = new Histogram(image);
		} catch (HistogramException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public int getNumOutput() {
		return numOutput;
	}

	@Override
	public void setImage(ImageCls image) {
		histogram = image.getHistogram();
		
	}

	@Override
	public float[] extract() {
		float[] features = new float[1];
		features[0] = histogram.getPeakValue(color_mode) / (float) histogram.getColorLength(color_mode);
		return features;
	}

	@Override
	public String getName() {
		return ImageHelper.getColorName(color_mode)+" Histogram Peak";
	}
}
